package com.fulihui.usercore.core.processor.auth;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.PostConstruct;

import org.springframework.context.support.ApplicationObjectSupport;
import org.springframework.stereotype.Component;

/**
 * @author Willard.Hu on 2016/11/9 0009.
 */
@Component
public class AuthProcessorRegister extends ApplicationObjectSupport {

    private Map<String, AuthProcessor> processorMap = new HashMap<>();

    @PostConstruct
    private void init() {
        Map<String, AbstractAuthProcessor> beans = getApplicationContext().getBeansOfType(
            AbstractAuthProcessor.class);
        for (AbstractAuthProcessor bean : beans.values()) {
            processorMap.put(bean.authType(), bean);
        }
    }

    public AuthProcessor getProcessor(String authType) {
        return processorMap.get(authType);
    }
}
